package com.flyan.game.motafx.ui;

import com.flyan.game.motafx.config.GameConfig;
import javafx.geometry.Point2D;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.FontSmoothingType;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;

/**
 * 左侧信息栏
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/2/5
 */
public class LeftInfoPane extends VBox {

    private final Text floorInfo;
    private final Text hpInfo;
    private final Text ackInfo;
    private final Text defInfo;
    private final Text goldInfo;

    public LeftInfoPane() {
        setPrefSize(GameConfig.LEFT_INFO_PANE_WIDTH, GameConfig.LEFT_INFO_PANE_HEIGHT);
        setStyle("-fx-border-color: red");

        /* 楼层信息 */
        floorInfo = newText(GameConfig.LEFT_INFO_PANE_FLOOR_COORDINATE,
                GameConfig.LEFT_INFO_PANE_WIDTH - (GameConfig.HORIZONTAL_BORDER_SIZE * 2),
                TextAlignment.CENTER,
                "魔塔 ? 层");
        floorInfo.setStyle("-fx-font-size: 13");

        /* 血量 */
        hpInfo = newText(GameConfig.LEFT_INFO_PANE_HP_COORDINATE,
                GameConfig.GRID_SIZE * 2,
                TextAlignment.RIGHT,
                "?");
        hpInfo.setStyle("-fx-font-size: 11");

        /* 攻击力 */
        ackInfo = newText(GameConfig.LEFT_INFO_PANE_ACK_COORDINATE,
                GameConfig.GRID_SIZE * 2,
                TextAlignment.RIGHT,
                "?");
        ackInfo.setStyle("-fx-font-size: 11");

        /* 防御力 */
        defInfo = newText(GameConfig.LEFT_INFO_PANE_DEF_COORDINATE,
                GameConfig.GRID_SIZE * 2,
                TextAlignment.RIGHT,
                "?");
        defInfo.setStyle("-fx-font-size: 11");

        /* 金币 */
        goldInfo = newText(GameConfig.LEFT_INFO_PANE_GOLD_COORDINATE,
                GameConfig.GRID_SIZE * 2,
                TextAlignment.RIGHT,
                "0");
        goldInfo.setStyle("-fx-font-size: 11");

        /* 道具栏 */

    }

    public void update() {

    }

    private Text newText(Point2D translatePoint, double wrappingWidth, TextAlignment alignment, String text) {
        Text t = new Text();
        t.setFontSmoothingType(FontSmoothingType.LCD);
        t.setFill(Color.WHITE);
        t.setTranslateX(translatePoint.getX());
        t.setTranslateY(translatePoint.getY());
        t.setWrappingWidth(wrappingWidth);
        t.setTextAlignment(alignment);
        t.setText(text);
        getChildren().add(t);
        return t;
    }

    public Text getFloorInfo() {
        return floorInfo;
    }

    public Text getHpInfo() {
        return hpInfo;
    }

    public Text getAckInfo() {
        return ackInfo;
    }

    public Text getDefInfo() {
        return defInfo;
    }

    public Text getGoldInfo() {
        return goldInfo;
    }

}
